package com.monkar.java.dao;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.stereotype.Repository;

import com.monkar.java.bean.PersonalDTO;
import com.monkar.java.bean.UsuarioDTO;
import com.monkar.java.constans.QuerysMySQL;
import com.monkar.java.constans.RowMapperConstans;

@Repository
public class PersonalDAO {

	
	private SimpleJdbcTemplate simpleJdbcTemplate;
    private JdbcTemplate jdbcTemplate;
	private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
	
	@Autowired
	public void init(DataSource dataSource) {
		this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
		this.jdbcTemplate=new JdbcTemplate(dataSource);
		this.namedParameterJdbcTemplate=new NamedParameterJdbcTemplate(dataSource);
		
	} 
	
	@SuppressWarnings("unchecked")
	public List<PersonalDTO> obtenerPersonalXUsuario(UsuarioDTO usuario){
		StringBuffer sqlb= new StringBuffer(QuerysMySQL.LISTAR_PERSONAL);
		sqlb.append("and usuario= '"+usuario.getUsuario()+"' and clave= md5('"+usuario.getClave()+"')");
		String sql= sqlb.toString();
		
		System.out.println(sql);
		
		return this.jdbcTemplate.query(sql,new RowMapperConstans.PersonalMapper());
		
	}
}
